﻿using System;
using System.Globalization;
using System.Linq;

namespace Klinkby.T4
{
    using FxRate = Quote<double>;
    using FxQueue = IQueue<Quote<double>>;
    
    /// <summary>Extends the generated class</summary>
    /// <typeparam name="T"></typeparam>
    [Serializable]
    partial class Quote<T> : MarshalByRefObject where T: struct
    {
        public override string ToString()
        {
            return string.Format(
                CultureInfo.InvariantCulture,
                "{0} : {1:0.00}",
                _symbol,
                _rate);
        }
    }

    // make 10 random quotes and write them to the console
    class Program
    {
        static void Main(string[] args)
        {
            var calculateRate = new Func<int, FxRate>(
                (i) => new FxRate("EURUSD", Math.Sin(i / 10.0) * 10)
            );

            FxQueue rates = Enumerable.Range(1, 10)
                            .Aggregate(
                                Queue<FxRate>.Empty,
                                (queue, i) => queue.Enqueue(calculateRate(i))
                            );

            foreach (var rate in rates)
                Console.WriteLine(rate);
        }
    }
}